Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 572 - Oil deposits / Intentando ayudar / tarif.c
blob9968279b641cb7bdd663b002d594e6c55957976b
1 #include <stdio.h>
2 #include <assert.h>
4 int recur(int,int);
6 #define ROW 100
7 #define COL 100
9 char array[ROW][COL];
10 int m,n;
12 int main(void)
16 int l_1,l_2;
17 int grid = 0,z=0;
18 char ch;
20 for (;;)
22 scanf("%d %d", &m, &n);
24 if(m==0)
27 return 0;
30 assert(m>=1 && m<=100 && n>=1 && n<=100);
31 for(l_1=0;l_1<m;l_1++)
33 for(l_2=0;l_2<n;l_2++)
35 scanf("%c", &ch);
36 while(ch=='\n' || ch=='\r' || ch==' ')
38 scanf("%c",&ch);
41 assert(ch=='@' || ch=='*');
42 array[l_1][l_2] = ch;
48 for(l_1=0;l_1<m;l_1++)
50 for(l_2=0;l_2<n;l_2++)
52 if(array[l_1][l_2]=='@')
54 z++;
55 array[l_1][l_2]='c';
56 recur(l_1,l_2);
61 //assert(z<=100); //This generates a Runtime Error... Bad problem description!
62 printf("%d\n", z);
64 z=0;
66 return 0;
70 int recur(int mm, int nn)
74 int k,i,j;
76 int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
77 int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
79 for( k = 0; k < 8; k++)
81 i = mm + dx[k];
82 j = nn + dy[k];
84 if(i >= 0 && i < m && j >= 0 && j < n)
85 if(array[i][j]=='@')
88 array[i][j] = 'c';
89 recur(i,j);
93 return 0;